﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace Chaine.Models
{

    public class ChangePasswordModel
    {
        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Current password")]
        public string OldPassword { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "New password")]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm new password")]
        [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }

    public class LogOnModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }

    public class RegisterModel
    {
        public ObjectId Id { get; set; }

        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        [BsonIgnore]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        [BsonIgnore]
        public string ConfirmPassword { get; set; }
        public string RealName { get; set; }
        [Display(Name = "Email address")]
        [Required]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }
        public string Mobile { get; set; }
        public string Gender { get; set; }
        public string Nationality { get; set; }
        public string Address { get; set; }
        public string PostCode { get; set; }
        /// <summary>
        /// email是否验证成功
        /// </summary>
        public bool EmailIsValidated { get; set; }

        /// <summary>
        /// 是否经过管理员的审核
        /// </summary>
        public bool IsChecked { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool IsDeleted { get; set; }


        [BsonIgnore]
        public string Status
        {
            get
            {
                //是否是系统管理员
                if (Roles.IsUserInRole(this.UserName, "admin"))
                    return "Admin";
                //email没有通过验证
                if (!EmailIsValidated)
                    return "Email Is Invalidatived";
                //email通过验证但是管理员没有审核
                if (EmailIsValidated && !IsChecked)
                    return "Is Not Approved";
                if (IsChecked && EmailIsValidated)
                    return "Member";
                return string.Empty;
            }
        }
    }

    /// <summary>
    /// 系统用户角色
    /// </summary>
    public enum UserRole
    {
        /// <summary>
        /// 管理员
        /// </summary>
        Admin,
        /// <summary>
        /// 普通成员
        /// </summary>
        Member,
    }

}
